package svc

import (
	"github.com/bwmarrin/snowflake"
	_ "github.com/lib/pq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"xialou_platform/services/system/model"
	"xialou_platform/services/system/rpc/internal/config"
)

type ServiceContext struct {
	Config         config.Config
	Flake          *snowflake.Node
	SysUserModel   model.SysUserModel
	SysConfigModel model.SysConfigModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn("postgres", c.Postgres.DataSource)
	flake, err := snowflake.NewNode(c.SnowflakeNode)
	if err != nil {
		panic(err)
	}
	return &ServiceContext{
		Config:         c,
		Flake:          flake,
		SysUserModel:   model.NewSysUserModel(conn, c.CacheRedis),
		SysConfigModel: model.NewSysConfigModel(conn, c.CacheRedis),
	}
}
